/**
 * 
 */
package cn.gov.msa.ws;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import cn.gov.msa.service.DictionaryDetailService;
import cn.gov.msa.util.InfoObjUtil;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

/**   
* @Title: DictService.java 
* @Package cn.gov.msa.ws 
* @Description: TODO(用一句话描述该文件做什么) 
* @author 何宇江  
* @date 2018年3月12日 上午10:08:56 
*/
public class DictService {
    
	/*
	 * 字典明细查询服务
	 * */
	public static String dictionary(ApplicationContext ctx, String params) throws Exception {
		int result = 0;
		String info = InfoObjUtil.Error_NODATA;
	    JSONObject jsonResult = new JSONObject();
		
		try{
			
	        DictionaryDetailService dictionaryDetailService = (DictionaryDetailService) ctx.getBean("DictionaryDetailService");  
			
	        
			JSONObject jsonParams = JSONObject.fromObject(params);
	        
	        String dictcode = jsonParams.has("dictcode") ? jsonParams.getString("dictcode") : "";
	        String pitemcode = jsonParams.has("pitemcode") ? jsonParams.getString("pitemcode") : "";
	        String itemname = jsonParams.optString("itemname");
	        JSONArray jaResult = JSONArray.fromObject(dictionaryDetailService.selectDictionary(dictcode, pitemcode, itemname));

	        if(jaResult.size() > 0){
	        	result = 1;
	        	info = InfoObjUtil.Success_select_OK;
	        	jsonResult.put("datas", jaResult);
	        }
		}
		catch(Exception e){
			e.printStackTrace();
        	result = 2;
        	info = InfoObjUtil.Exption_msg;
		}
		

    	jsonResult.put("result", result);
    	jsonResult.put("info", info);

		
		return jsonResult.toString();
	}
}
